package com.itheima.sc.service.sms;

import cn.hutool.core.convert.Convert;
import com.itheima.sc.api.sms.SmsHomeRecommendProductApi;
import com.itheima.sc.pojo.sms.HomeRecommendProduct;
import com.itheima.sc.pojo.sms.HomeRecommendProduct;
import com.itheima.sc.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SmsHomeRecommendProductService {

    @DubboReference
    private SmsHomeRecommendProductApi recommendProductApi;

    //添加首页推荐
    public void addRecommendProducts(List<HomeRecommendProduct> recommendProducts) {
        recommendProductApi.addRecommendProducts(recommendProducts);
    }

    //批量删除
    public void deleteRecommendProducts(List<Long> ids) {
         recommendProductApi.deleteRecommendProducts(ids);
    }

    //分页查询首页推荐
    public PageResult selectRecommendProductList(Map<String, String> param) {
        String productName = param.get("productName");
        Integer page = Convert.toInt(param.get("pageNum"));
        Integer pageSize = Convert.toInt(param.get("pageSize"));
        Integer recommendStatus = Convert.toInt(param.get("recommendStatus"));
        return recommendProductApi.selectRecommendProductList(page, pageSize, recommendStatus,productName);
    }
    //批量修改首页推荐的状态
    public void updateRecommendProductStatus(List<Long> ids, Integer status) {
        recommendProductApi.updateRecommendProductStatus(ids,status);
    }
    //修改首页推荐
    public void updateRecommendProductSort(Long id, Integer sort) {
        HomeRecommendProduct RecommendProduct=new  HomeRecommendProduct();
        RecommendProduct.setId(id);
        RecommendProduct.setSort(sort);
        recommendProductApi.updateRecommendProductSort(RecommendProduct);
    }
}
